var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        id: "",
        goods: {},
        start_time: "",
        end_time: "",
        status: "",
        aid: "",
        active_status: "",
        countDownTime: 0,
        isAddGroup: !1,
        btnTest: "更多活动",
        Participants: [],
        activiyWinMember: [],
        showWechatshar: !1,
        userMorePage: 1,
        awardMorePage: 1
    },
    onLoad: function(t) {
        this.data.id = t.id, this.getData();
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en,
            timestamp: Date.parse(new Date()) / 1e3,
            action: t.action
        });
    },
    goDetail: function(t) {
        console.log(t), "detail" == t.currentTarget.dataset.key && wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + this.data.aid + "&name=zhpGroup"
        });
    },
    clickBtn: function(t) {
        console.log(this.data.status, this.data.isAddGroup), this.data.status && this.data.isAddGroup || (2 == this.data.status || this.data.isAddGroup ? wx.navigateTo({
            url: "/packageB/member/group/GroupList/GroupList?types=zhpGroup"
        }) : wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + this.data.aid + "&name=zhpGroup"
        }));
    },
    getData: function() {
        var e = this, i = this, s = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group.get-group");
        a._postNetWork({
            url: s,
            data: {
                group_id: i.data.id
            },
            success: function(a) {
                var s, r = a.data;
                1 == r.result ? (console.log(r), i.setData((t(s = {}, "goods.title", r.data.goods_title), 
                t(s, "goods.thumb", r.data.goods_thumb), t(s, "goods.price", r.data.goods_price), 
                t(s, "goods.group_price", r.data.group_price), t(s, "start_time", Number(r.data.start_time)), 
                t(s, "end_time", Number(r.data.end_time)), t(s, "aid", r.data.activity_id), s)), 
                console.log(i.data.timestamp, i.data.end_time, i.data.start_time), i.data.timestamp < i.data.start_time ? (i.data.countDownTime = i.getTimeDifference(i.start_time), 
                e.setData({
                    status: 0
                }), r.data.member_group_info && r.data.member_group_info.order_id && e.setData({
                    isAddGroup: !0
                }), i.data.btnTest = i.data.isAddGroup ? "邀请好友" : "去参团", i.data.countDownTime = i.getTimeDifference(i.data.start_time)) : i.data.timestamp <= r.data.end_time && i.data.timestamp >= r.data.start_time ? (e.setData({
                    status: 1
                }), r.data.member_group_info && r.data.member_group_info.order_id && e.setData({
                    isAddGroup: !0
                }), i.data.btnTest = i.data.isAddGroup ? "邀请好友" : "去参团", i.data.countDownTime = i.getTimeDifference(i.data.end_time)) : e.setData({
                    status: 2
                }), i.setData({
                    countDownTime: i.data.countDownTime,
                    isAddGroup: i.data.isAddGroup,
                    btnTest: i.data.btnTest,
                    active_status: 0 == i.data.status ? "距离活动开始时间" : 1 == i.data.status ? "距离本轮结束" : "活动已结束"
                }), e.getMembers(), e.getActiviyWinMember()) : wx.showToast({
                    title: r.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    finishChange: function() {
        this.getData();
    },
    getMembers: function() {
        var t = this, e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group.get-group-member");
        a._postNetWork({
            url: e,
            data: {
                group_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    for (var i = [], s = 0; s < e.data.data.length; s += 5) i.push(e.data.data.slice(s, s + 5));
                    t.setData({
                        Participants: i,
                        ParticipantsLen: e.data.last_page
                    });
                } else wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    getActiviyWinMember: function() {
        var t = this, e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group.get-activiy-member-win");
        a._postNetWork({
            url: e,
            data: {
                activity_id: this.data.aid
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    for (var i = [], s = 0; s < e.data.data.length; s += 5) i.push(e.data.data.slice(s, s + 5));
                    t.setData({
                        activiyWinMember: i,
                        activiyWinMemberLen: e.data.last_page
                    });
                } else wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    swiperUser: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.key;
        if ("autoplay" == t.detail.source && "user" == a) {
            if (this.data.userMorePage >= this.data.ParticipantsLen) return;
            this.setData({
                userMorePage: this.data.userMorePage + 1
            }), this.getMore("user");
        }
    },
    swiperUser_2: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.key;
        if ("autoplay" == t.detail.source && "member" == a) {
            if (this.data.awardMorePage >= this.data.activiyWinMemberLen) return;
            this.setData({
                awardMorePage: this.data.awardMorePage + 1
            }), this.getMore("member");
        }
    },
    getMore: function(t) {
        var e, i, s = this, r = this;
        "user" == t ? (e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group.get-group-member"), 
        i = {
            group_id: r.data.id,
            page: r.data.userMorePage
        }) : (e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group.get-activiy-member-win"), 
        i = {
            activity_id: r.data.aid,
            page: r.data.awardMorePage
        }), a._postNetWork({
            url: e,
            data: i,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) if ("user" == t) {
                    for (var i = 0; i < e.data.data.length; i += 5) r.data.Participants.push(e.data.data.slice(i, i + 5));
                    s.setData({
                        Participants: r.data.Participants,
                        ParticipantsLen: e.data.last_page
                    });
                } else {
                    for (var o = 0; o < e.data.data.length; o += 5) r.data.activiyWinMember.push(e.data.data.slice(o, o + 5));
                    s.setData({
                        activiyWinMember: r.data.activiyWinMember,
                        activiyWinMemberLen: e.data.last_page
                    });
                } else wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    getTimeDifference: function(t) {
        var a = Date.parse(new Date()), e = t < 1e12 ? 1e3 * t : t;
        return e - a > 0 ? e - a : e - a <= 0 ? 0 : void 0;
    },
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            userMorePage: 1,
            awardMorePage: 1
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.title ? this.data.title : "",
            path: "/packageA/detail_v2/detail_v2?id=" + this.data.aid + "&name=zhpGroup",
            imageUrl: this.data.goods.thumb
        };
    }
});